package com.letoken.platform.repo.app.manager;

import com.alibaba.fastjson.JSON;
import com.letoken.platform.pub.util.BeanUtil;
import com.letoken.platform.repo.app.dao.AppUserLoginLogMapper;
import com.letoken.platform.repo.app.po.AppUserLoginLog;
import com.letoken.platform.repo.app.po.AppUserSession;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

/**
 * 用户登录记录
 *
 * @Author: letokenlabs
 * @Date: 2021/4/14  11:02
 */
@Log4j2
@Repository
public class AppUserLoginLogManager {

    @Autowired
    private AppUserLoginLogMapper appUserLoginLogMapper;

    public void insertAppUserLoginLog(AppUserSession appUserSession) {
        AppUserLoginLog appUserLoginLog = new AppUserLoginLog();
        BeanUtil.quickCopy(appUserSession, appUserLoginLog);
        appUserLoginLog.setAppUserId(appUserSession.getId());
        appUserLoginLog.setCreateTime(LocalDateTime.now());
        log.info("insertAppUserLoginLog  loginLog insert success, user info: [{}]", JSON.toJSONString(appUserLoginLog));
        int res = appUserLoginLogMapper.insert(appUserLoginLog);
        if (res < 1) {
            log.error("insertAppUserLoginLog error. fail to insert loginLog:[{}] ", JSON.toJSONString(appUserLoginLog));
        }
    }

}
